﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Announcement.DAL.DataSetGarageDetailsTableAdapters;
using Announcement.Model;

namespace Announcement
{
    public partial class GarageRead : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void fvGarage_ItemCommand(object sender, FormViewCommandEventArgs e)
        {
       
        }

        protected void fvGarage_DataBound(object sender, EventArgs e)
        {
            var garageDetailsRows = new T_Garage_DetailsTableAdapter();
            DataTable dt = new DataTable();
            //取得Gid
            HiddenField hfId = (HiddenField)fvGarage.FindControl("hfId");
            int gId = Convert.ToInt32(hfId.Value);
            if (gId != 0)
            {
                dt = garageDetailsRows.GetDataByGid(gId);
            }
            lvGarageDetails.Items.Clear();
            lvGarageDetails.DataSource = dt;
            lvGarageDetails.DataBind();
        }

        protected void lbtnBack_Click(object sender, EventArgs e)
        {
            string id = Request.QueryString["Id"];
            Response.Redirect("ApplyRead.aspx?Id=" + id);
        }

        protected void AnnouncementButton_Click(object sender, EventArgs e)
        {
            //取得表单数据
            GarageTable gt = new GarageTable();
            Label labDistrictName = (Label)fvGarage.FindControl("labDistrictName");
            gt.DistrictName = labDistrictName.Text;
            Label labDevelopersName = (Label)fvGarage.FindControl("labDevelopersName");
            gt.DevelopersName = labDevelopersName.Text;
            Label labStartDate = (Label)fvGarage.FindControl("labStartDate");
            gt.StartDate = DateTime.Parse(labStartDate.Text);
            Label labEndDate = (Label)fvGarage.FindControl("labEndDate");
            gt.EndDate = DateTime.Parse(labEndDate.Text);
            Label labFillDate = (Label)fvGarage.FindControl("labFillDate");
            gt.FillDate = DateTime.Parse(labFillDate.Text);
            Label labHouseSoldRate = (Label)fvGarage.FindControl("labHouseSoldRate");
            gt.HouseSoldRate = Decimal.Parse(labHouseSoldRate.Text);
            Label labGarageSold = (Label)fvGarage.FindControl("labGarageSold");
            gt.GarageSold = Convert.ToInt32(labGarageSold.Text);
            Label labGarageUnsold = (Label)fvGarage.FindControl("labGarageUnsold");
            gt.GarageUnsold = Convert.ToInt32(labGarageUnsold.Text);

            Session["GarageTable"] = gt;
            Response.Redirect("Sell.aspx?isPrn=true");
        }

        protected void lbtnExit_Click(object sender, EventArgs e)
        {
            Session["UserName"] = null;
            Response.Redirect("~/Login.aspx");
        }
    }
}
